package handler

import (
	"github.com/gin-gonic/gin"
	"liao/api/request"
	"liao/glodal"
	"liao/inits"
	"liao/pkg"
	"math/rand"
	"net/http"
	"strconv"
	"time"
)

func SendSms(context *gin.Context) {
	var req request.SendSms
	if err := context.ShouldBind(&req); err != nil {
		context.JSON(http.StatusBadRequest, gin.H{
			"code":    http.StatusBadRequest,
			"message": "参数失败",
		})
		return
	}
	code := rand.Intn(9000) + 1000
	pkg.SendSms(req.Mobile, strconv.Itoa(code))
	glodal.Rdb.Set(inits.Ctx, "sendSms:"+req.Mobile, code, time.Hour*3)
	context.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "短信发送成功",
	})
}
